<?php
//引用数据库连接文件
require_once 'conn.php';

//设置字符集，避免中文乱码
$db->query("SET NAMES UTF8");

//定义SQL语句
$sql="select studentid,studentname from student";

//执行SQL语句，返回结果
$result=$db->query($sql);

if($result){
    //获取关联数组
    // while($row=$result->fetch_assoc()){
    //     echo $row['studentid'],',',$row['studentname'],"<br>";
    //  }

    // while($row=$result->fetch_row()){
    //     echo $row['0'],',',$row['1'],"<br>";
    //  }

    //      while($row=$result->fetch_array()){
    //     echo $row['0'],',',$row['studentname'],"<br>";
    //  }

     while($row=$result->fetch_object()){
        echo $row->studentid,',',$row->studentname,"<br>";
     }

     //释放结果集
     $result->close();
}

//关闭连接
$db->close();
?>

